<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>医保服务数据管理</title>
    <link rel="stylesheet" href="./bootstrap.min.css">
    <link rel="stylesheet" href="./site.css">
    <style>
        .dropdown-submenu {
            position: relative;
        }

        .dropdown-submenu .dropdown-menu {
            top: 0;
            left: 100%;
            margin-top: -1rem;
            margin-left: -1rem;
        }
    </style>
    <style>
        .alert-container {
            position: fixed;
            left: 50%;
            transform: translateX(-50%);
            z-index: 9999;
        }

        .alert-container:not(:first-child) {
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div b-529uds4zl5="" class="position-fixed bottom-0 end-0 p-3" style="z-index: 5" id="toastContainer"></div>

    <div b-529uds4zl5="" class="container">
        <div b-529uds4zl5="" id="liveAlertPlaceholder"></div>
        <main b-529uds4zl5="" role="main" class="pb-3">
            <style>
                .table-container {
                    height: 300px;
                    /* 根据你的行高和期望显示的行数来调整这个值 */
                    overflow-y: auto;
                    /* 当内容超出时显示垂直滚动条 */
                    border: 1px solid #ccc;
                    /* 可选，为容器添加边框 */
                }

                table {
                    width: 100%;
                    /* 表格宽度 */
                    table-layout: auto;
                    /* 使用固定表格布局 */
                    border-collapse: collapse;
                    /* 合并边框 */
                }

                th,
                td {
                    border: 1px solid #ccc;
                    /* 边框样式 */
                    padding: 8px;
                    /* 内边距 */
                    text-align: left;
                    /* 文本对齐方式 */
                    white-space: nowrap;
                    /* 防止内容换行 */
                    overflow: hidden;
                    /* 超出部分隐藏 */
                    text-overflow: ellipsis;
                    /* 超出部分显示省略号 */
                }
            </style>
            <div class="container mt-1">
                <div class="mb-3 row">
                    <h1 class="col-sm-2 col-form-label-lg">医保人员信息插入</h1>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="certno" name="certno" placeholder="删除时请在这里填写人员身份信息">
                    </div>
                    <div class="col-sm-5 form-group">
                        <button type="button" class="btn btn-primary" onclick="Insertpsninfo()">新增人员</button>
                        <button type="button" class="btn btn-primary" onclick="Deletepsninfo()">删除人员</button>
                    </div>
                    <div class="form-group">
                        <textarea id="psninfo" class="form-control" rows="6"
                            placeholder="请输入医保返回的1101出参，必须符合JSON格式"></textarea>
                    </div>
                </div>
                <div class="mb-3 row">
                    <h1 class="col-sm-2 col-form-label-lg">医保处方信息处理</h1>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="auth_rxno" name="auth_rxno"
                            placeholder="删除时请在这里填写处方授权编号">
                    </div>
                    <div class="col-sm-5 form-group">
                        <button type="button" class="btn btn-primary" onclick="InsertOpspInfo()">新增处方</button>
                        <button type="button" class="btn btn-primary" onclick="DeleteOpspInfo()">删除处方</button>
                    </div>
                    <div class="col-sm-6">
                        <textarea id="opspinput" class="form-control" rows="6"
                            placeholder="新增处方时请在此处填写浙江省医保7203入参，必须符合JSON格式"></textarea>
                    </div>
                    <div class="col-sm-6">
                        <textarea id="opspoutput" class="form-control" rows="6"
                            placeholder="新增处方时请在此处填写浙江省医保7203出参，必须符合JSON格式"></textarea>
                    </div>
                </div>
                <div class="mb-3 row">
                    <h1 class="col-sm-2 col-form-label-lg">事前事中商品处理</h1>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="med_list_codg" name="med_list_codg"
                            placeholder="国家编码">
                    </div>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="rule_name" name="rule_name" placeholder="规则名称">
                    </div>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="vola_cont" name="vola_cont" placeholder="规则说明">
                    </div>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="vola_evid" name="vola_evid" placeholder="违规理由">
                    </div>
                    <div class="col-sm-2 form-group">
                        <button type="button" class="btn btn-primary"
                            onclick="InsertRiskconserviceProductInfo()">新增规则</button>
                        <button type="button" class="btn btn-primary"
                            onclick="DeleteRiskconserviceProductInfo()">删除规则</button>
                    </div>
                </div>
                <div class="mb-3 row">
                    <h1 class="col-sm-2 col-form-label-lg">云服务医保数据查看</h1>
                    <div class="col-sm-2">
                        <select class="form-select" id="codingType" aria-label="Default select example">
                            <option value="1">人员信息</option>
                            <option value="2">事前事中控制商品</option>
                        </select>
                    </div>
                    <div class="col-sm-2">
                        <input type="password" class="form-control" id="pwd" name="pwd" placeholder="鉴权参数">
                    </div>
                    <div class="col-sm-2">
                        <input type="number" class="form-control" min="1" max="200" id="pagesize" name="pagesize"
                            placeholder="每页条数" aria-describedby="pagesizeHelp">
                    </div>
                    <div class="col-sm-4 form-group">
                        <button type="button" class="btn btn-primary" onclick="search(1)">查询</button>
                        <button type="button" class="btn btn-primary" onclick="search(0)">查询下一页</button>
                    </div>
                </div>
                <div class="table-responsive table-container">
                    <table class="table table-bordered table-striped" id="resultTable">
                    </table>
                </div>
            </div>
        </main>
    </div>
    <script src="./jquery.min.js"></script>
    <script src="./bootstrap.bundle.min.js"></script>
    <script src="./site.js"></script>
    <script src="./component.js"></script>
    <script type="text/javascript">
        console.log(window.location);
        window.urlHeader = window.location.origin;

        window.onload = function () {

        };

        function Insertpsninfo() {
            try {
                var input = document.getElementById('psninfo').value;
                var psninfo = JSON.parse(input);

            } catch (e) {
                showAlert("输入参数格式错误！请检查输入参数是否符合JSON格式！异常信息：" + e.message, "danger", true, 3);
                return;
            }
            var apiUrl = `${window.urlHeader}/FsiAdminApi/InsertPsnInfo`;

            // 创建请求头对象
            const headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('Authorization', 'Bearer ' + localStorage.getItem("token"));

            // 创建请求选项对象
            const requestOptions = {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(psninfo),
            };
            fetchAll(apiUrl, requestOptions)
                .then(data => {
                    if (data.code !== 0) {
                        createModal("myModal", "接口提示", "错误代码：" + data.code + "<br>错误原因：" + data.msg, function () {
                        });
                        showModal('myModal');
                        return;
                    } else {
                        createModal("myModal", "接口提示", data.data, function () {
                        });
                        showModal('myModal');
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        }
        function InsertOpspInfo() {
            try {
                var opspinput = document.getElementById('opspinput').value;
                var opspinputinfo = JSON.parse(opspinput);

            } catch (e) {
                showAlert("无效的处方信息入参JSON,请确认！异常信息：" + e.message, "danger", true, 3);
                return;
            }
            try {
                var opspoutput = document.getElementById('opspoutput').value;
                var opspoutputinfo = JSON.parse(opspoutput);
            } catch (e) {
                showAlert("无效的处方信息出参JSON,请确认！异常信息：" + e.message, "danger", true, 3);
                return;
            }
            const opspinfo = {
                inputJson: opspinputinfo,
                outputJson: opspoutputinfo,
            };
            var apiUrl = `${window.urlHeader}/FsiAdminApi/InsertEpcInfo`;
            // 创建请求头对象
            const headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('Authorization', 'Bearer ' + localStorage.getItem("token"));

            // 创建请求选项对象
            const requestOptions = {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(opspinfo),
            };
            fetchAll(apiUrl, requestOptions)
                .then(data => {
                    if (data.code !== 0) {
                        createModal("myModal", "接口提示", "错误代码：" + data.code + "<br>错误原因：" + data.msg, function () {
                        });
                        showModal('myModal');
                        return;
                    } else {
                        createModal("myModal", "接口提示", data.data, function () {
                        });
                        showModal('myModal');
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        }
        function InsertRiskconserviceProductInfo() {
            const ProductInfo = {
                med_list_codg: document.getElementById('med_list_codg').value,
                rule_name: document.getElementById('rule_name').value,
                vola_cont: document.getElementById('vola_cont').value,
                vola_evid: document.getElementById('vola_evid').value,
            };

            var apiUrl = `${window.urlHeader}/FsiAdminApi/InsertRiskconserviceProductInfo`;
            // 创建请求头对象
            const headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('Authorization', 'Bearer ' + localStorage.getItem("token"));

            // 创建请求选项对象
            const requestOptions = {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(ProductInfo),
            };
            fetchAll(apiUrl, requestOptions)
                .then(data => {
                    if (data.code !== 0) {
                        createModal("myModal", "接口提示", "错误代码：" + data.code + "<br>错误原因：" + data.msg, function () {
                        });
                        showModal('myModal');
                        return;
                    } else {
                        createModal("myModal", "接口提示", data.data, function () {
                        });
                        showModal('myModal');
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        }
        function DeleteRiskconserviceProductInfo() {
            const ProductInfo = {
                med_list_codg: document.getElementById('med_list_codg').value,
            };

            var apiUrl = `${window.urlHeader}/FsiAdminApi/DeleteRiskconserviceProductInfo`;
            // 创建请求头对象
            const headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('Authorization', 'Bearer ' + localStorage.getItem("token"));

            // 创建请求选项对象
            const requestOptions = {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(ProductInfo),
            };
            fetchAll(apiUrl, requestOptions)
                .then(data => {
                    if (data.code !== 0) {
                        createModal("myModal", "接口提示", "错误代码：" + data.code + "<br>错误原因：" + data.msg, function () {
                        });
                        showModal('myModal');
                        return;
                    } else {
                        createModal("myModal", "接口提示", data.data, function () {
                        });
                        showModal('myModal');
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        }
        function DeleteOpspInfo() {
            const OpspInfo = {
                auth_rxno: document.getElementById('auth_rxno').value,
            };

            var apiUrl = `${window.urlHeader}/FsiAdminApi/DeleteEpcInfo`;
            // 创建请求头对象
            const headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('Authorization', 'Bearer ' + localStorage.getItem("token"));

            // 创建请求选项对象
            const requestOptions = {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(OpspInfo),
            };
            fetchAll(apiUrl, requestOptions)
                .then(data => {
                    if (data.code !== 0) {
                        createModal("myModal", "接口提示", "错误代码：" + data.code + "<br>错误原因：" + data.msg, function () {
                        });
                        showModal('myModal');
                        return;
                    } else {
                        createModal("myModal", "接口提示", data.data, function () {
                        });
                        showModal('myModal');
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        }
        function Deletepsninfo() {
            const Psninfo = {
                certno: document.getElementById('certno').value,
            };

            var apiUrl = `${window.urlHeader}/FsiAdminApi/DeletePsnInfo`;
            // 创建请求头对象
            const headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('Authorization', 'Bearer ' + localStorage.getItem("token"));

            // 创建请求选项对象
            const requestOptions = {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(Psninfo),
            };
            fetchAll(apiUrl, requestOptions)
                .then(data => {
                    if (data.code !== 0) {
                        createModal("myModal", "接口提示", "错误代码：" + data.code + "<br>错误原因：" + data.msg, function () {
                        });
                        showModal('myModal');
                        return;
                    } else {
                        createModal("myModal", "接口提示", data.data, function () {
                        });
                        showModal('myModal');
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        }
        let page = 1;
        function search(nowpage) {
            if (nowpage == 0) {
                page = page + 1;
            } else {
                page = nowpage;
            }
            var urlheader = window.urlHeader;
            var codingType = document.getElementById('codingType').value;
            var pwd = document.getElementById('pwd').value;
            var pagesize = document.getElementById('pagesize').value;
            if (pagesize == "") {
                pagesize = 100;
            }
            if (pagesize > 200) {
                showAlert("单次请求条数超过200，过大的单次请求条数会对服务造成压力！请重新输入！", 'warning', true, 3);
                return;
            }
            var apiUrl = "";
            console.log(codingType);
            if (codingType == 1) {
                apiUrl = `${urlheader}/FsiAdminApi/SelectFsiTableData?&pwd=${pwd}&tablename=fsi_psninfo&pagesize=${pagesize}&nowpage=${page}`;
            }
            else if (codingType == 2) {
                apiUrl = `${urlheader}/FsiAdminApi/SelectFsiTableData?&pwd=${pwd}&tablename=fsi_riskconserviceproduct&pagesize=${pagesize}&nowpage=${page}`;
            }
            else {
                showAlert("下拉选择框异常!", 'warning', true, 3);
                return;
            }
            // 创建请求头对象
            const headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('Authorization', 'Bearer ' + localStorage.getItem("token"));

            // 创建请求选项对象
            const requestOptions = {
                method: 'GET',
                headers: headers
            };
            fetchAll(apiUrl, requestOptions)
                .then(data => {
                    if (data.code !== 0) {
                        createModal("myModal", "接口提示", "错误代码：" + data.code + "<br>错误原因：" + data.msg, function () {
                        });
                        showModal('myModal');
                        return;
                    }
                    showAlert("数据获取成功", 'success', true, 3);
                    const resultTable = document.getElementById('resultTable');
                    resultTable.innerHTML = '';

                    // 获取数据的第一项来动态生成表头
                    const headers = Object.keys(data.data[0]).map(header => `<th>${header}</th>`);
                    // 添加一个表示操作列的表头
                    //headers.push(`<th>操作</th>`);
                    const headersHTML = headers.join('');
                    // 创建表头行
                    const headerRow = `<tr>${headersHTML}</tr>`;
                    resultTable.innerHTML += headerRow;

                    // 遍历数据并添加到表格中
                    data.data.forEach(item => {
                        const dataCells = Object.values(item).map(value => `<td>${value}</td>`).join('');
                        //const actionButton = `<td><button class="btn btn-primary" onclick="SelectOne()" >详情</button></td>`;
                        const row = `<tr>${dataCells}</tr>`;
                        resultTable.innerHTML += row;
                    });
                })
                .catch(error => {
                    console.error(error);
                });
        }
    </script>
</body>

</html>